{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import metrics\n",
    "from sklearn import ensemble\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.preprocessing import Imputer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv('data/titanic/train.csv',index_col='PassengerId')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.concat([df,pd.get_dummies(df['Pclass'], prefix='Pclass')],axis=1)\n",
    "df.drop(['Pclass'],axis=1,inplace=True)\n",
    "df = pd.concat([df,pd.get_dummies(df['Sex'], prefix='Sex')],axis=1)\n",
    "df.drop(['Sex'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X_train, X_test, y_train, y_test = train_test_split(\n",
    "    df[['Pclass_1','Pclass_2','Pclass_3', 'Sex_female','Sex_male','Age','Fare']].values, \n",
    "    df[['Survived']].values, \n",
    "    test_size=0.33)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "imp = Imputer(missing_values='NaN', strategy='mean', axis=0)\n",
    "X_train =imp.fit_transform(X_train)\n",
    "X_test = imp.transform(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GradientBoostingClassifier(criterion='friedman_mse', init=None,\n",
       "              learning_rate=0.1, loss='deviance', max_depth=3,\n",
       "              max_features=None, max_leaf_nodes=None,\n",
       "              min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "              min_samples_leaf=60, min_samples_split=2,\n",
       "              min_weight_fraction_leaf=0.0, n_estimators=100,\n",
       "              presort='auto', random_state=None, subsample=1.0, verbose=0,\n",
       "              warm_start=False)"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf = ensemble.GradientBoostingClassifier(min_samples_leaf=60)\n",
    "clf.fit(X_train, y_train.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xd8VfX9x/HXJ2EjQ4bKFBAQQUEh\ngohVrAtQQXGB2krVUqXWulptxUXtz1nrHkApTtwKKoqKqHUghL0UEFCCKFP2yPj8/vheQogZN+Pm\n5ibv5+ORB/ece+45nxMgn3zH+XzN3REREQFIincAIiJSfigpiIhINiUFERHJpqQgIiLZlBRERCSb\nkoKIiGRTUhARkWxKClKhmNkKM9thZlvN7EczG2tm++U65lgz+8jMtpjZJjN7y8w65jqmrpk9aGbf\nR871bWS7UT7XNTO72szmm9k2M0szs1fM7IhY3q9IaVNSkIroTHffDzgSOAr42543zKwn8D4wHmgK\ntAbmAJ+bWZvIMdWAyUAnoA9QF+gJrAe653PNh4A/A1cDDYD2wJvA6UUN3syqFPUzIqXF9ESzVCRm\ntgK43N0/jGzfC3Ry99Mj2/8D5rn7sFyfexdY6+6/NbPLgX8Ch7j71iiu2Q74Gujp7tPyOeZj4Dl3\nHx3ZHhKJ87jItgNXAdcAVYD3gG3ufkOOc4wHPnH3B8ysKfAIcDywFfi3uz8cxbdIpEBqKUiFZWbN\ngb7A0sh2LeBY4JU8Dn8ZOCXy+mTgvWgSQsRJQ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Yw4GTI9/LVOC6\nQq4jlYjKXEh5tCPygzGnqsCjkT70TEJ9n9y+BG42s+bA6+6+xMxOAroB0yMlPGoSEkxenjezHcAK\nQnnmQ4Hl7r448v7TwB+BRwnrMvzHzN4G3o72xtx9rZkti9S5WQJ0AD6PnLcocVYjlCbJ+X0638yG\nEv5fNyEsSDM312ePiez/PHKdaoTvmwigpCCJ41rgJ6ALoYX7i8Vy3P0FM/sKOB2YaGZ/IKxo9bS7\n/y2Ka1yUs1CemTXI66BIvZ7uhCJt5wJXAb8uwr28CJwPfA284e5u4Sd01HECMwjjCY8AA82sNXAD\ncLS7bzSzsYTCcbkZ8IG7Dy5CvFKJqPtIEkU9YHWkhv5vCMXT9mFmbYBlkS6T8YRulMnAuWZ2QOSY\nBhb9GtTfAK3MrG1k+zfAJ5E++HruPpGQrLrk8dkthLLdeXmDsOLWYEKCoKhxRgrC3QIcY2YdCCuT\nbQM2mdmBQN98YpkK9NpzT2ZW28zyanVJJaWkIIniceASM5tD6HLZlscx5wPzzWw2YQ2FZyIzfoYD\n75vZXOADQtdKodx9J6Fq5StmNg/IAp4k/IB9O3K+z8i7T34s8OSegeZc590ILAIOdvdpkX1FjjMy\nVvEvQlXUOYR1mr8GXiB0Se0xEnjPzKa4+1rCzKhxket8Sfh+igCqkioiIjmopSAiItmUFEREJJuS\ngoiIZFNSEBGRbEoKIiKSTUlBRESyKSmIiEi2/wfR72JxpQgKyAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7ff7d16cac88>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "y_preds = clf.predict_proba(X_test)\n",
    "\n",
    "# take the second column because the classifier outputs scores for\n",
    "# the 0 class as well\n",
    "preds = y_preds[:,1]\n",
    "\n",
    "# fpr means false-positive-rate\n",
    "# tpr means true-positive-rate\n",
    "fpr, tpr, _ = metrics.roc_curve(y_test, preds)\n",
    "\n",
    "auc_score = metrics.auc(fpr, tpr)\n",
    "\n",
    "plt.title('ROC Curve')\n",
    "plt.plot(fpr, tpr, label='AUC = {:.2f}'.format(auc_score))\n",
    "\n",
    "# it's helpful to add a diagonal to indicate where chance \n",
    "# scores lie (i.e. just flipping a coin)\n",
    "plt.plot([0,1],[0,1],'r--')\n",
    "\n",
    "plt.xlim([-0.1,1.1])\n",
    "plt.ylim([-0.1,1.1])\n",
    "plt.ylabel('True Positive Rate')\n",
    "plt.xlabel('False Positive Rate')\n",
    "\n",
    "plt.legend(loc='lower right')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>feature</th>\n",
       "      <th>importance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Fare</td>\n",
       "      <td>0.394527</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Age</td>\n",
       "      <td>0.278655</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Sex_male</td>\n",
       "      <td>0.114824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Sex_female</td>\n",
       "      <td>0.098209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Pclass_3</td>\n",
       "      <td>0.070676</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Pclass_1</td>\n",
       "      <td>0.034127</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Pclass_2</td>\n",
       "      <td>0.008981</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      feature  importance\n",
       "6        Fare    0.394527\n",
       "5         Age    0.278655\n",
       "4    Sex_male    0.114824\n",
       "3  Sex_female    0.098209\n",
       "2    Pclass_3    0.070676\n",
       "0    Pclass_1    0.034127\n",
       "1    Pclass_2    0.008981"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame({\n",
    "    'feature':['Pclass_1','Pclass_2','Pclass_3', 'Sex_female','Sex_male','Age','Fare'],\n",
    "    'importance':clf.feature_importances_\n",
    "}).sort_values(\"importance\",ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Global TF Kernel (Python 3)",
   "language": "python",
   "name": "global-tf-python-3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
